﻿Public Class frmCapNhatTinBai
    Public _taikhoan As String
    Public Property Taikhoan() As String
        Get
            Return _taikhoan
        End Get
        Set(ByVal value As String)
            _taikhoan = value
        End Set
    End Property
    Private Sub btnHuyTin_Click(sender As System.Object, e As System.EventArgs)
        Me.Close()
    End Sub
    Public _dangtinDTO As New DangTinDTO
    Public tableLoaiNha As New DataTable
    Public tableDiaChi As New DataTable
    Public tableLoaiTin As New DataTable
    Public tableKhuVuc As New DataTable
    Private Sub frmCapNhatTinBai_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim diachiDTO As New DiaChiDTO
        Dim diachiBUS As New DiaChiBUS
        '----------------------------------------------------------------------------------------------------
        Dim loaiNhaDTO As New LoaiNhaDTO
        Dim loaiNhaBUS As New LoaiNhaBUS
        '----------------------------------------------------------------------------------------------------
        Dim loaitinDTO As New LoaiTinDTO
        Dim loaitinBUS As New LoaiTinBUS
        '----------------------------------------------------------------------------------------------------
        Dim kvDTO As New KhuVucDTO
        Dim kvBUS As New KhuVucBUS
        '----------------------------------------------------------------------------------------------------
        tableLoaiTin = loaitinBUS.GetAll()
        tableLoaiNha = loaiNhaBUS.GetAll()
        tableKhuVuc = kvBUS.GetAll()
        tableDiaChi = diachiBUS.GetAll()
        '------------------------------------------------------------------------------------------
        For i As Integer = 0 To tableDiaChi.Rows.Count - 1
            If Convert.ToInt32(tableDiaChi.Rows(i)("MaDiaChi").ToString()) = _dangtinDTO.MaDiaChi Then
                diachiDTO.MaDiaChi = Convert.ToInt32(tableDiaChi.Rows(i)("MaDiaChi").ToString())
                diachiDTO.Duong = tableDiaChi.Rows(i)("Duong").ToString()
                diachiDTO.Phuong = tableDiaChi.Rows(i)("Phuong").ToString()
                diachiDTO.Quan = tableDiaChi.Rows(i)("Quan").ToString()
                diachiDTO.SoNha = tableDiaChi.Rows(i)("SoNha").ToString()
                Exit For
            End If
        Next
        '------------------------------------------------------------------------------------------
        For i As Integer = 0 To tableLoaiNha.Rows.Count - 1
            If Convert.ToInt32(tableLoaiNha.Rows(i)("MaLoaiNha").ToString()) = _dangtinDTO.MaLoaiNha Then
                cbLoaiNha.Items.Add(tableLoaiNha.Rows(i)("TenLoaiNha"))
                Exit For
            End If
        Next
        cbLoaiNha.SelectedIndex = 0
        '---------------------------------------------------------------------------------------------------
        For i As Integer = 0 To tableLoaiTin.Rows.Count - 1
            If Convert.ToInt32(tableLoaiTin.Rows(i)("MaLoaiTin").ToString()) = _dangtinDTO.MaLoaiTin Then
                cbLoaiTin.Items.Add(tableLoaiTin.Rows(i)("TenLoai"))
                Exit For
            End If
        Next
        cbLoaiTin.SelectedIndex = 0
        '----------------------------------------------------------------------------------------------------
        For i As Integer = 0 To tableKhuVuc.Rows.Count - 1
            If tableKhuVuc.Rows(i)("TenKhuVuc").ToString() = diachiDTO.Quan Then
                cbQuan.Items.Add(tableKhuVuc.Rows(i)("TenKhuVuc"))
                Exit For
            End If
        Next
        cbQuan.SelectedIndex = 0
        '----------------------------------------------------------------------------------------------------
        For i As Integer = 0 To tableKhuVuc.Rows.Count - 1
            cbQuan.Items.Add(tableKhuVuc.Rows(i)("TenKhuVuc"))
        Next

        For i As Integer = 0 To tableLoaiNha.Rows.Count - 1
            cbLoaiNha.Items.Add(tableLoaiNha.Rows(i)("TenLoaiNha"))
        Next

        For i As Integer = 0 To tableLoaiTin.Rows.Count - 1
            cbLoaiTin.Items.Add(tableLoaiTin.Rows(i)("TenLoai"))
        Next
        '----------------------------------------------------------------------------------------------------
        cbSuaChua.Items.Add(_dangtinDTO.SucChua)
        cbSuaChua.SelectedIndex = 0
        '----------------------------------------------------------------------------------------------------
        cbSuaChua.Items.Add("1")
        cbSuaChua.Items.Add("2")
        cbSuaChua.Items.Add("3")
        cbSuaChua.Items.Add("4")
        cbSuaChua.Items.Add("5")
        cbSuaChua.Items.Add("6")
        cbSuaChua.Items.Add("7")
        cbSuaChua.Items.Add("8")
        cbSuaChua.Items.Add("9")
        cbSuaChua.Items.Add("10")
        '----------------------------------------------------------------------------------------------------
        txtDienTich.Text = _dangtinDTO.DienTich
        txtGiaThue.Text = _dangtinDTO.GiaThue
        txtTieuDe.Text = _dangtinDTO.TieuDe
        txtPhuong.Text = diachiDTO.Phuong
        txtDuong.Text = diachiDTO.Duong
        txtSoNha.Text = diachiDTO.SoNha
        '----------------------------------------------------------------------------------------------------
        If _dangtinDTO.ChoNamThue = 1 Then
            ckChoNamThue.Checked = True
        Else
            ckChoNamThue.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dangtinDTO.ChoNuThue = 1 Then
            ckChoNuThue.Checked = True
        Else
            ckChoNuThue.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dangtinDTO.GanCho = 1 Then
            ckGanCho.Checked = True
        Else
            ckGanCho.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dangtinDTO.ChoNauAn = 1 Then
            ckNauAn.Checked = True
        Else
            ckNauAn.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dangtinDTO.OChungChu = 1 Then
            ckChungChu.Checked = True
        Else
            ckChungChu.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dangtinDTO.OGhep = 1 Then
            ckOGhep.Checked = True
        Else
            ckOGhep.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dangtinDTO.Internet = 1 Then
            ckInternet.Checked = True
        Else
            ckInternet.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dangtinDTO.TruyenHinhCap = 1 Then
            ckTruyenHinhCap.Checked = True
        Else
            ckTruyenHinhCap.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
        If _dangtinDTO.GanTramXeBuyt = 1 Then
            ckXeBuyt.Checked = True
        Else
            ckXeBuyt.Checked = False
        End If
        '----------------------------------------------------------------------------------------------------
    End Sub
    Private Function KiemTra() As Boolean
        If txtDienTich.Text = "" Or txtGiaThue.Text = "" Or txtSoNha.Text = "" Or txtSoNha.Text = "" Or txtDuong.Text = "" Or txtPhuong.Text = "" Or cbQuan.Text = "" Or cbSuaChua.Text = "" Then
            Return False
        End If
        Return True
    End Function
    Private Sub btnThemMoi_Click(sender As System.Object, e As System.EventArgs) Handles btnThemMoi.Click
        Dim nhaBUS As New DangTinBUS
        _dangtinDTO.DienTich = Convert.ToSingle(txtDienTich.Text)
        _dangtinDTO.GiaThue = Convert.ToInt32(txtGiaThue.Text)
        _dangtinDTO.TieuDe = txtTieuDe.Text
        _dangtinDTO.SucChua = Convert.ToInt32(cbSuaChua.Text)

        For i As Integer = 0 To tableLoaiNha.Rows.Count - 1
            If tableLoaiNha.Rows(i)("TenLoaiNha").ToString() = cbLoaiNha.Text Then
                _dangtinDTO.MaLoaiNha = Convert.ToInt32(tableLoaiNha.Rows(i)("MaLoaiNha").ToString())
                Exit For
            End If
        Next
        For i As Integer = 0 To tableLoaiTin.Rows.Count - 1
            If tableLoaiTin.Rows(i)("TenLoai").ToString() = cbLoaiTin.Text Then
                _dangtinDTO.MaLoaiTin = Convert.ToInt32(tableLoaiTin.Rows(i)("MaLoaiTin").ToString())
                Exit For
            End If
        Next
        If ckXeBuyt.Checked = True Then
            _dangtinDTO.GanTramXeBuyt = 1
        Else
            _dangtinDTO.GanTramXeBuyt = 0
        End If
        If ckOGhep.Checked = True Then
            _dangtinDTO.OGhep = 1
        Else
            _dangtinDTO.OGhep = 0
        End If
        If ckNauAn.Checked = True Then
            _dangtinDTO.ChoNauAn = 1
        Else
            _dangtinDTO.ChoNauAn = 0
        End If
        If ckChungChu.Checked = True Then
            _dangtinDTO.OChungChu = 1
        Else
            _dangtinDTO.OChungChu = 0
        End If
        If ckInternet.Checked = True Then
            _dangtinDTO.Internet = 1
        Else
            _dangtinDTO.Internet = 0
        End If
        If ckTruyenHinhCap.Checked = True Then
            _dangtinDTO.TruyenHinhCap = 1
        Else
            _dangtinDTO.TruyenHinhCap = 0
        End If
        If ckGanCho.Checked = True Then
            _dangtinDTO.GanCho = 1
        Else
            _dangtinDTO.GanCho = 0
        End If
        If ckChoNamThue.Checked = True Then
            _dangtinDTO.ChoNamThue = 1
        Else
            _dangtinDTO.ChoNamThue = 0
        End If
        If ckChoNuThue.Checked = True Then
            _dangtinDTO.ChoNuThue = 1
        Else
            _dangtinDTO.ChoNuThue = 0
        End If
        _dangtinDTO.TinhTrang = 1
        nhaBUS.Update(_dangtinDTO)
        Me.Close()
    End Sub

    Private Sub SimpleButton2_Click(sender As System.Object, e As System.EventArgs) Handles SimpleButton2.Click
        Me.Close()
    End Sub
End Class